<template>
  <Dialog title="操作记录" v-model="dialogVisible" style="width: 70% !important">
    <ContentWrap>
      <el-table
        stripe
        border
        v-loading="detailLoading"
        :data="list"
        :header-cell-style="{ background: '#F3F4F7', color: '#555' }"
      >
        <el-table-column label="重量" align="center" prop="weight"/>
        <el-table-column label="状态" align="center" prop="waybillStatus">
          <template #default="scope">
            <dict-tag :type="DICT_TYPE.PURCHASE_WAYBILL_STATUS" :value="scope.row.waybillStatus"/>
          </template>
        </el-table-column>
        <el-table-column label="描述" align="center" prop="waybillDescription">
          <template #default="{row}">
            <el-popover :width="600" :content="row.waybillDescription" placement="top" effect="dark">
              <template #reference>
                <div class="ellipsis">{{ row.waybillDescription }}</div>
              </template>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column label="位置名称" align="center" prop="locationName"/>
        <el-table-column label="时间" align="center" prop="createTime" :formatter="dateFormatter"/>
      </el-table>
      <!-- 分页 -->
      <Pagination
        :total="total"
        v-model:page="queryParams.pageNo"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
  </Dialog>
</template>
<script setup lang="ts">
import {dateSFormatter, dateFormatter} from '@/utils/formatTime'
import {DICT_TYPE} from '@/utils/dict'
import * as purchaseWaybillApi from "@/api/purchaseWaybill";

const dialogVisible = ref(false) // 弹窗的是否展示
const detailLoading = ref(false) // 表单的加载中
const total = ref(0) // 列表的总页数
const list = ref([])
/** 初始化 **/
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  waybillId: ''
})

/** 查询列表 */
const getList = async () => {
  detailLoading.value = true
  try {
    const data = await purchaseWaybillApi.waybillRecords(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    detailLoading.value = false
  }
}

/** 打开弹窗 */
const open = async (id: number) => {
  queryParams.pageNo = 1
  dialogVisible.value = true
  queryParams.waybillId = id
  getList()
}
defineExpose({open}) // 提供 open 方法
</script>
<style lang="scss" scoped>
.ellipsis {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>
